package dk.aau.walkietalkie.network;

import java.util.Set;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;

public class ConnectivityChecker {

	public static boolean isWifiEnabled(Context cont) {
		WifiManager wifi = (WifiManager) cont
				.getSystemService(Context.WIFI_SERVICE);

		if (wifi.isWifiEnabled()) {
			return true;
		}
		return false;
	}

	public static boolean isWifiConnected(Context cont) {

		if (isWifiEnabled(cont)) {
			ConnectivityManager connManager = (ConnectivityManager) cont
					.getSystemService(Context.CONNECTIVITY_SERVICE);
			NetworkInfo mWifi = connManager
					.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

			if (mWifi.isConnected()) {
				return true;
			}
		}
		return false;
	}

	public static boolean isBluetoothEnabled(Context cont) {
		BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
				.getDefaultAdapter();
		if (mBluetoothAdapter == null) {
			return false;
		} else {
			if (mBluetoothAdapter.isEnabled()) {
				return true;
			}
			return false;
		}
	}

	public static boolean isBluetoothConnected(Context cont) {
		if (isBluetoothEnabled(cont)) {
			Set<BluetoothDevice> pairedDevices = BluetoothAdapter
					.getDefaultAdapter().getBondedDevices();
			if (pairedDevices.size() > 0) {
				return true;
			}
		}
		return false;

	}

}
